<template>
    <!--弹出窗-->
    <modal ref="modal_1"
           :title="title"
           :isCloseConfirm="this.editable"
           :fullscreen="this.fullscreen"
           top="3%"
           width="80%"
           :close-on-click-modal="true"
           @modalOpened="opened"
           @modalClose="closed">

        <avue-form :option="option"
                   ref="form"
                   v-model="form"
                   @submit="onSubmit">

            <template #toNo v-if="this.editable">
                <el-autocomplete
                        style="width: 100%;"
                        v-model="form.toNo"
                        :fetch-suggestions="querytoNo"
                        :placeholder="toNoPlaceholder"
                        :trigger-on-focus="false"
                        @select="selectToNo"
                        :fit-input-width="true"
                        :disabled="(!!this.form.id) || hasItem"
                ></el-autocomplete>
            </template>

            <template #toName v-if="this.editable">
                <el-input v-model="form.toName" readonly :placeholder="toNamePlaceholder" @click="selectToName" :disabled="(!!this.form.id) || hasItem"/>
            </template>

<!--            <template #deliNo v-if="this.editable">-->
<!--                <div style="display: flex;flex-direction: start;">-->
<!--                    <el-input v-model="form.deliNo" placeholder="请输入出仓单号"/>-->
<!--                    <el-tooltip content="修正查询" placement="top" >-->
<!--                        <el-button-->
<!--                                icon="Search"-->
<!--                                plain-->
<!--                                @click="() => showDeliNo()"-->
<!--                        >-->
<!--                        </el-button>-->
<!--                    </el-tooltip>-->
<!--                </div>-->
<!--            </template>-->

            <template #companyName v-if="this.editable">
                <el-input v-model="form.companyName" readonly placeholder="请选择银行信息" @click="selectBankInfo" :disabled="!!this.form.id || hasItem"/>
            </template>

            <template #stockOutItem>
                <stock-out-item ref="stockOutItem" :outType="this.form.outType" :toDept="this.form.toDept" :toName="this.form.toName" :logisticsNo="this.form.logisticsNo"
                                :toNo="this.form.toNo" :isRole="isRole" :fromDept="this.form.fromDept" :bankId="this.form.bankId" @disabledFiled="disabledFiled">

                </stock-out-item>
            </template>
        </avue-form>

        <!--底部按钮块, 默认只有"取消"按钮-->
        <template #footerButton>
            <el-button
                    type="primary"
                    v-if="(permission.stock_in_main_add || permission.stock_in_main_edit) && editable"
                    :loading="btnLoading"
                    @click="this.$refs.form.submit()"
            >确认单据
            </el-button>
            <el-button @click="$refs.modal_1.handleClose()">关闭</el-button>
        </template>
        <select-customer  ref="selectCustomer"  @success="setCustomerNo"/>
        <select-supplier  ref="selectSupplier"  @success="setSupplier"/>
        <select-bank  ref="selectBank"  @success="setBank"/>
    </modal>
</template>

<script>
    import {add, getDetail,saveStockOut} from "@/api/anwise/stock/stock_out_main";
    import {stockHomeSelect} from "@/api/anwise/stock_home";
    import {userCompany} from "@/api/anwise/common";
    import {findSupplierByDeptId,remoteList as supplierRemoteList,ownerList} from "@/api/anwise/supplier";
    import {remoteList as customerRemoteList} from '@/api/anwise/customer/customer';
    import {mapGetters} from "vuex";
    import {Pattern} from "@/utils/validate.js";
    import {dateFormat} from "@/utils/date.js";
    import {getDictionary} from "@/api/system/dictbiz";
    import StockOutItem from './stock_out_item.vue';
    import selectCustomer from './select_customer.vue';
    import selectSupplier from './select_supplier.vue';
    import selectBank from './select_bank.vue';

    export default {
        components: {
            StockOutItem,
            selectCustomer,
            selectSupplier,
            selectBank
        },
        data() {
            return {
                emits: ["success"],
                dept:'',
                editable: false,
                title: "出仓单信息",
                isCloseConfirm: false,
                fullscreen: false,
                form: {},
                query: {},
                loading: true,
                btnLoading: false,
                supType:"",
                toNoPlaceholder:"",
                toNamePlaceholder:"",
                isRole:"",
                supplierData:{},
                anwiseData:{},
                outTypeDic:[],
                hasItem:false,
                option: {
                    card: true,
                    tabs: true,
                    tabsActive: 1,
                    height: 'auto',
                    calcHeight: 30,
                    labelWidth: 150,
                    menuWidth: 120,
                    submitBtn: false,
                    emptyBtn: false,
                    column: [
                        {
                            label: "出仓单号",
                            prop: "idNo",
                            type: "input",
                            span:8,
                            placeholder:'保存后自动生成单号',
                            disabled:true,
                        },
                        {
                            label: "所属机构",
                            prop: "fromName",
                            type: "input",
                            span:8,
                            disabled:true,
                        },
                        {
                            label: "交货方式",
                            prop: "deliMeth",
                            type: "select",
                            filterable: true,
                            span:8,
                            dicUrl: '/api/blade-system/dict-biz/dictionary?code=deli_type',
                            props: {
                                label: 'dictValue',
                                value: 'dictKey',
                            },
                            dataType: 'string',
                            rules: [{
                                required: false,
                                message: "请输入交货方式",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "出仓类型",
                            prop: "outType",
                            type: "select",
                            // dicUrl: "/blade-system/dict-biz/dictionary?code=out_type",
                            dicData:[],
                            filterable: true,
                            clearable:false,
                            props: {
                                label: 'dictValue',
                                value: 'dictKey',
                            },
                            change:	({column,value})=>{this.changeOutType(column,value)},
                            dataType: 'string',
                            span:8,
                            value:"其它出仓",
                            disabled:false,
                            rules: [{
                                required: true,
                                message: "请选择出仓类型",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "收货组织编号",
                            prop: "toNo",
                            type: "input",
                            overHidden: true,
                            sortable: true,
                            span:8,
                            rules: [{
                                required: true,
                                message: "请输入编号",
                                trigger: "blur"
                            }],
                            display:true,
                        },
                        {
                            label: "收货组织名称",
                            prop: "toName",
                            type: "input",
                            overHidden: true,
                            sortable: true,
                            span:8,
                            rules: [{
                                required: true,
                                message: "请选择名称",
                                trigger: "blur"
                            }],
                            display:true,
                        },
                        // {
                        //     label: "币别",
                        //     prop: "rmb",
                        //     type: "select",
                        //     filterable: true,
                        //     span:8,
                        //     dicUrl: '/api/blade-system/dict-biz/dictionary?code=rmb',
                        //     props: {
                        //         label: 'dictValue',
                        //         value: 'dictKey',
                        //     },
                        //     dataType: 'string',
                        //     disabled:true,
                        //     rules: [{
                        //         required: false,
                        //         message: "请输入币别",
                        //         trigger: "blur"
                        //     }],
                        //     display:true
                        // },
                        // {
                        //     label: "结算方式",
                        //     prop: "payType",
                        //     type: "select",
                        //     filterable:true,
                        //     span:8,
                        //     disabled:true,
                        //     dicUrl: '/api/blade-system/dict-biz/dictionary?code=pay_type',
                        //     props: {
                        //         label: 'dictValue',
                        //         value: 'dictKey',
                        //     },
                        //     dataType: 'string',
                        //     rules: [{
                        //         required: false,
                        //         message: "请输入结算方式",
                        //         trigger: "blur"
                        //     }],
                        //     display:true
                        // },
                        {
                            label: "收款方",
                            prop: "companyName",
                            type: "input",
                            readonly:true,
                            span:8,
                            rules: [{
                                required: true,
                                message: "请输入收款方",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "销售方式",
                            prop: "salesType",
                            type: "select",
                            filterable: true,
                            span:8,
                            dicUrl: '/api/blade-system/dict-biz/dictionary?code=sales_type',
                            props: {
                                label: 'dictValue',
                                value: 'dictKey',
                            },
                            dataType: 'string',
                            display:'false',
                            rules: [{
                                required: false,
                                message: "请输入销售方式",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "出仓日期",
                            prop: "outDate",
                            type: "date",
                            valueFormat: 'YYYY-MM-DD',
                            format:'YYYY-MM-DD',
                            span:8
                        },
                        {
                            label: "工厂名称",
                            prop: "factoryName",
                            type: "input",
                            disabled:true,
                            span:8,
                            rules: [{
                                required: false,
                                message: "请输入交货地址",
                                trigger: "blur"
                            }],
                        },

                        {
                            label: "交货地址",
                            prop: "deliAddr",
                            type: "input",
                            overHidden: true,
                            sortable: true,
                            span:8,
                            rules: [{
                                required: false,
                                message: "请输入交货地址",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "统一仓位",
                            prop: "allStock",
                            type: "select",
                            filterable: true,
                            display:false,
                            span:8,
                            dicUrl: '/api/blade-anwise/stock_home/select?switchType=销售出仓',
                            props: {
                                label: 'stockName',
                                value: 'id',
                            },
                            dataType: 'string',
                            change:	({column,value,s1})=>{this.changeAllStock(column,value,s1)},
                            rules: [{
                                required: false,
                                message: "请输入统一仓位",
                                trigger: "blur"
                            }],
                        },
                        {
                            label: "出仓备注",
                            prop: "remark",
                            type: "textarea",
                            maxlength: 2000,
                            minRows:2,
                            span: 24,
                        },
                    ],
                    group: [
                        {
                            icon: 'el-icon-house',
                            label: '出仓项信息',
                            prop: 'group1',
                            column: [
                                {
                                    label: '',
                                    prop: 'stockOutItem',
                                    className: 'addPadding',
                                    span: 24,
                                    labelWidth: 0,
                                    formslot: true,
                                    display: true,
                                },
                            ],
                        },
                    ]
                },
                data: []
            };
        },
        computed: {
            ...mapGetters(["permission","userInfo"]),
            permissionList() {
                return {
                    addBtn: this.validData(this.permission.stock_out_main_add, false),
                    viewBtn: this.validData(this.permission.stock_out_main_view, false),
                    delBtn: this.validData(this.permission.stock_out_main_delete, false),
                    editBtn: this.validData(this.permission.stock_out_main_edit, false)
                };
            },
            ids() {
                let ids = [];
                this.selectionList.forEach(ele => {
                    ids.push(ele.id);
                });
                return ids.join(",");
            },
            isAnwiseProdRole(){//安伟生产角色
                return this.userInfo.role_id.includes("1717966761333272578");
            },
            isJiagongshangRole(){//加工商角色
                return this.userInfo.role_id.includes("1717966543397236738");
            },
            isPurchaseRole(){//采购商角色
                return this.userInfo.role_id.includes("1728951498503839746");
            },
            isAnwiseDept(){
                return '1683670943851282433';
            },
        },
        mounted() {
            this.init();
        },
        methods: {
            changeAllStock(column,value,s1) {
                console.log("column",column);
                let outItem = this.$refs.stockOutItem.$refs.tableRef.getTableData().fullData;
                if (outItem.length > 0) {
                    outItem.forEach(item => {
                        item.stockId = value;
                    })
                }
            },
            disabledFiled(hasItem) {
                this.hasItem = hasItem;
            },
            init() {
                this.form.outDate = dateFormat(new Date(),'yyyy-MM-dd');
                this.form.deliDate = dateFormat(new Date(),'yyyy-MM-dd');
                userCompany().then(res=>{
                    if (res.data.success) {
                        this.dept = res.data.data;
                        if (!this.dept) {
                            this.$message({
                                type: "error",
                                message: "用户无组织机构信息，请联系安伟工作人员！"
                            });
                            return;
                        } else {
                            this.isRole = this.dept.bodyType;
                        }
                    }
                })
                findSupplierByDeptId().then(res => {
                    if (res.data.success) {
                        this.supplierData = res.data.data;
                        if (!this.supplierData) {
                            this.$message({
                                type: "error",
                                message: "用户无组织机构信息，请联系安伟工作人员！"
                            });
                            return;
                        }
                    }
                })
                findSupplierByDeptId(null,this.isAnwiseDept).then(res=>{
                    if (res.data.success) {
                        this.anwiseData = res.data.data;
                    }
                })
            },
            showDeliNo(){

            },
            querytoNo(val,cb) {
                this.form.toName = "";
                this.form.companyName = "";
                this.form.bankId = "";
                if (!this.form.outType) {
                    this.$message({
                        type: "error",
                        message: "请先选择出仓类型!"
                    });
                    return;
                }
                if(this.form.outType === "销售出仓"){
                    this.queryCustomer(val,cb);
                }else if(this.form.outType === "生产出仓"){
                    this.querySupplierPro(val,cb,1);
                }else if(this.form.outType === "领料出仓"){
                    this.querySupplierPro(val,cb,1);
                }else if(this.form.outType === "退货出仓"){
                    this.querySupplierPro(val,cb,1);
                }else if(this.form.outType === "退料出仓"){
                    this.querySupplierPur(val,cb,2);
                }
            },
            queryCustomer(val,cb){
                const reg = Pattern.number;
                if (!reg.test(val)) {
                    this.$message({
                        type: "error",
                        message: "客户账号只能为数字!"
                    });
                    return;
                }

                customerRemoteList(val).then(res => {
                    if (res.data.success) {
                        let customerList = [];
                        res.data.data.forEach(item => {
                            customerList.push({
                                value:item.custNo +" - "+item.custName,
                                toDept: item.deptId,
                                customerId: item.id,
                                toNo: item.custNo,
                                toName: item.custName,
                            });
                        })
                        cb(customerList);
                    }
                })
            },
            querySupplierPro(val,cb,type){
                const reg = Pattern.number;
                if (!reg.test(val)) {
                    this.$message({
                        type: "error",
                        message: "加工商账号只能为数字!"
                    });
                    return;
                }

                supplierRemoteList(val,type).then(res => {
                    if (res.data.success) {
                        let customerList = [];
                        res.data.data.forEach(item => {
                            customerList.push({
                                value:item.supNo +" - "+item.supName,
                                toDept: item.deptId,
                                toNo: item.supNo,
                                toName: item.supName,
                            });
                        })
                        cb(customerList);
                    }
                })
            },
            querySupplierPur(val,cb,type){
                const reg = Pattern.number;
                if (!reg.test(val)) {
                    this.$message({
                        type: "error",
                        message: "采购商账号只能为数字!"
                    });
                    return;
                }

                ownerList(val,type,this.dept.id).then(res => {
                    if (res.data.success) {
                        let customerList = [];
                        res.data.data.forEach(item => {
                            customerList.push({
                                value:item.supNo +" - "+item.supName,
                                toDept: item.deptId,
                                toNo: item.supNo,
                                toName: item.supName,
                            });
                        })
                        cb(customerList);
                    }
                })
            },
            setBank(row) {
                console.log(row)
                this.form.companyName = row.companyName;
                this.form.rmb = row.rmb;
                this.form.bankId = row.id;
                this.$refs.orderItem.bankId= row.id;
            },
            selectBankInfo() {
                if (this.form.toNo && this.form.toName)  {
                    this.$refs.selectBank.showSelect(this.form.customerId);
                } else {
                    this.$message({
                        type: "error",
                        message: "请先选择客户信息!"
                    });
                }
            },
            selectToNo(item) {
                console.log('item',item);
                this.form.toDept = item.toDept;
                this.form.toNo = item.toNo;
                this.form.toName = item.toName;
                this.form.customerId = item.customerId;
            },
            selectToName(){
                if (!this.form.outType) {
                    this.$message({
                        type: "error",
                        message: "请先选择出仓类型!"
                    });
                    return;
                }
                if(this.form.outType === "销售出仓"){
                    this.$refs.selectCustomer.showSelect();
                }else if(this.form.outType === "生产出仓"){
                    this.$refs.selectSupplier.showSelect("加工商");
                }else if(this.form.outType === "领料出仓"){
                    this.$refs.selectSupplier.showSelect("加工商");
                }else if(this.form.outType === "退货出仓"){
                    this.$refs.selectSupplier.showSelect("加工商");
                }else if(this.form.outType === "退料出仓"){
                    this.$refs.selectSupplier.showSelect("采购商",this.dept.id);
                }
            },
            setSupplier(row){
                this.form.toDept = row.deptId;
                this.form.toNo = row.supNo;
                this.form.toName = row.supName;
                this.form.deliAddr = row.supAddr;
            },
            setCustomerNo(row) {
                this.form.toDept = row.deptId;
                this.form.customerId = row.id;
                this.form.toNo = row.custNo;
                this.form.toName = row.custName;
                this.form.companyName = "";
                this.form.bankId = "";
            },
            async validItemEvent() {
                const $table = this.$refs.stockOutItem.$refs.tableRef
                let errMap = undefined;
                await $table.fullValidate().then((err) => {
                    errMap=err;
                    console.log("err",err)
                })
                return errMap;
            },
            async onSubmit(form, done) {
                const $table = this.$refs.stockOutItem.$refs.tableRef
                let checkItem = false;
                const errMap = await this.validItemEvent();

                if (errMap) {
                    this.$message({
                        type: 'error',
                        message: '出仓项信息有误！',
                    });
                    checkItem = true;
                    done();
                    return;
                }
                if (!checkItem) {
                    this.btnLoading = true;
                    form.addList = $table.getInsertRecords();
                    form.updateList = $table.getUpdateRecords();
                    form.deleteList = $table.getRemoveRecords();
                    const itemList = $table.getTableData().fullData;
                    if (!itemList || itemList.length < 1) {
                        this.$message({
                            type: 'error',
                            message: '无出仓项信息！',
                        });
                        this.btnLoading = false;
                        done();
                        return;
                    }
                    saveStockOut(form).then(res => {
                        if (res.data.success) {
                            this.$message({
                                type: "success",
                                message: res.msg || "保存成功!"
                            });
                            setTimeout(() => {
                                this.btnLoading = false;
                                done();
                                this.$refs.modal_1.hide();
                            }, 1000)
                        } else {
                            this.$message({
                                type: "error",
                                message: res.msg || "保存失败!"
                            });
                        }
                    }).catch(err => {
                        console.log(err)
                        done();
                        this.btnLoading = false;
                    })

                }
            },
            changeOutType(column,value){
                const toName = this.findObject(this.option.column, 'toName');
                const toNo = this.findObject(this.option.column, 'toNo');
                const companyName = this.findObject(this.option.column, 'companyName');
                const salesType = this.findObject(this.option.column, 'salesType');
                const deliMeth = this.findObject(this.option.column, 'deliMeth');
                const deliAddr = this.findObject(this.option.column, 'deliAddr');
                const factoryName = this.findObject(this.option.column, 'factoryName');
                const allStock = this.findObject(this.option.column, 'allStock');
                if(this.type === "add"){
                    this.form.toName ="";
                    this.form.toNo ="";
                    this.form.toDept = "";
                    this.form.companyName = "";
                    this.form.deliAddr = "";
                }
                toName.display = true;
                toNo.display = true;
                companyName.display = true;
                salesType.display = false;
                if(this.isRole === 3){//加工商
                    deliMeth.display = false;
                    deliAddr.label = "交货仓位";
                }
                if(value === "销售出仓" && this.isRole === 1){//安韦主体
                    toName.label = "客户名称";
                    toNo.label = "客户账号";
                    this.toNoPlaceholder = "请输入客户账号";
                    this.toNamePlaceholder = "请选择客户名称";
                    salesType.display = true;
                    deliAddr.disabled = true;
                    factoryName.display = true;
                    allStock.display = true;
                }else if(value === "生产出仓" && this.isRole === 3){//加工商
                    toName.display = false;
                    toNo.display = false;
                    companyName.display = false;
                    this.form.toDept =this.anwiseData.deptId;
                    this.form.toName =this.anwiseData.supName;
                    this.form.toNo =this.anwiseData.supNo;
                    deliAddr.disabled = false;
                    factoryName.display = false;
                    allStock.display = false;
                }else if(value === "领料出仓"){//只有加工商
                    toName.label = "加工商名称";
                    toNo.label = "加工商账号";
                    this.toNoPlaceholder = "请输入加工商账号";
                    this.toNamePlaceholder = "请选择加工商名称";
                    this.form.toDept =this.supplierData.deptId;
                    this.form.toName =this.supplierData.supName;
                    this.form.toNo =this.supplierData.supNo;
                    companyName.display = false;
                    toName.display = false;
                    toNo.display = false;
                    deliAddr.disabled = false;
                    factoryName.display = false;
                    allStock.display = false;
                }else if(value === "退货出仓"){//只有安韦有
                    toName.label = "收货单位名称";
                    toNo.label = "收货单位账号";
                    this.toNoPlaceholder = "请输入收货单位账号";
                    this.toNamePlaceholder = "请选择收货单位名称";
                    companyName.display = false;
                    deliAddr.disabled = false;
                    factoryName.display = false;
                    allStock.display = false;
                }else if(value === "退料出仓"){//只有安韦有
                    toName.label = "采购商名称";
                    toNo.label = "采购商账号";
                    this.toNoPlaceholder = "请输入采购商账号";
                    this.toNamePlaceholder = "请选择采购商名称";
                    companyName.display = false;
                    deliAddr.disabled = false;
                    factoryName.display = false;
                    allStock.display = false;
                }else if( value === "工程领料" || value === "品质领料" || value === "样办出仓" ){
                    toName.display = false;
                    toNo.display = false;
                    this.form.toDept =this.supplierData.deptId;
                    this.form.toName =this.supplierData.supName;
                    this.form.toNo =this.supplierData.supNo;
                    companyName.display = false;
                    deliAddr.disabled = false;
                    factoryName.display = false;
                    allStock.display = false;
                }else if(value === "其它出仓" || value === "盘亏出仓" || value === "报废出仓"){
                    // toName.display = false;
                    toNo.display = false;
                    toName.label = "收货单位名称";
                    // toNo.label = "收货单位账号";
                    // this.toNoPlaceholder = "请输入收货单位账号";
                    this.toNamePlaceholder = "请选择收货单位名称";
                    this.form.toDept =this.supplierData.deptId;
                    this.form.toName =this.supplierData.supName;
                    this.form.toNo =this.supplierData.supNo;
                    companyName.display = false;
                    deliAddr.disabled = false;
                    factoryName.display = false;
                    allStock.display = false;
                }  else if(value === "调拨出仓"){
                    toName.display = false;
                    toNo.display = false;
                    this.form.toDept =this.supplierData.deptId;
                    this.form.toName =this.supplierData.supName;
                    this.form.toNo =this.supplierData.supNo;
                    companyName.display = false;
                    deliMeth.display = false;
                    deliAddr.display = false;
                    factoryName.display = false;
                    allStock.display = false;
                }
                stockHomeSelect(value).then(res=>{
                    if(res.data.success){
                        // const stockName = this.findObject(this.option.column, 'stockName');
                        // stockName.dicData = res.data.data;
                    }
                })
            },
            show(option) {
                const toName = this.findObject(this.option.column, 'toName');
                const toNo = this.findObject(this.option.column, 'toNo');
                this.outTypeDic = [];
                getDictionary({code:"out_type"}).then(res=>{
                    let dataDic = res.data.data;
                    dataDic = dataDic.filter(function(item) {
                        return item.dictValue !== "调拨出仓";
                    });
                    console.log(dataDic)
                    if(this.isRole === 1){//安韦
                        dataDic.forEach(item=>{
                            if( item.dictValue !== "领料出仓" && item.dictValue !== "生产出仓"){
                                if (item.dictValue == '销售出仓') {
                                    item.disabled = true;
                                }
                                this.outTypeDic.push(item);
                            }
                        })
                    }else if(this.isRole === 3){//加工商
                        dataDic.forEach(item=>{
                            if(item.dictValue !== "退货出仓" && item.dictValue !== "销售出仓"){
                                this.outTypeDic.push(item);
                            }
                            // if(item.dictValue === "生产出仓" || item.dictValue === "其它出仓"){
                            //         this.outTypeDic.push(item);
                            // }
                        })
                    }
                    this.findObject(this.option.column, 'outType').dicData = this.outTypeDic;
                })
                if (option.id) {
                    this.findObject(this.option.column, 'outType').disabled = true;
                    setTimeout(() => {
                        getDetail(option.id).then(res =>{
                            if (res.data.success) {
                                this.form = res.data.data;
                                this.$refs.stockOutItem.setData(this.editable, this.form.idNo)
                                console.log(this.form)
                            }
                        })
                    }, 500);
                } else {
                    this.form={}
                    this.hasItem=false;
                    this.form.outDate = dateFormat(new Date(),"yyyy-MM-dd");
                    this.form.deliDate = dateFormat(new Date(),'yyyy-MM-dd');
                    this.findObject(this.option.column, 'outType').disabled = false;
                    if(this.isRole === 3){
                        this.findObject(this.option.column, 'outType').value = "生产出仓";
                    }
                }
                this.form.fromName = this.supplierData.supName;
                this.form.fromNo = this.supplierData.supNo;
                this.form.fromDept = this.supplierData.deptId;
                // if(this.supplierData.deptId === this.isAnwiseDept){
                //     this.findObject(this.option.column, 'rmb').display = false;
                //     this.findObject(this.option.column, 'payType').display = false;
                // }else{
                //     this.form.rmb = this.supplierData.rmb;
                //     this.form.payType = this.supplierData.payType;
                // }
                this.title = option.title;
                this.type = option.type;
                this.option.detail = this.type === "view";
                this.editable = this.type !== "view";
                this.$refs.modal_1.show();
            },
            rowSave(row, done, loading) {
                add(row).then(() => {
                    this.onLoad(this.page);
                    this.$message({
                        type: "success",
                        message: "操作成功!"
                    });
                    done();
                }, error => {
                    loading();
                    window.console.log(error);
                });
            },
            rowUpdate(row, index, done, loading) {
                update(row).then(() => {
                    this.onLoad(this.page);
                    this.$message({
                        type: "success",
                        message: "操作成功!"
                    });
                    done();
                }, error => {
                    loading();
                    window.console.log(error);
                });
            },
            rowDel(row) {
                this.$confirm("确定将选择数据删除?", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        return remove(row.id);
                    })
                    .then(() => {
                        this.onLoad(this.page);
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                    });
            },
            handleDelete() {
                if (this.selectionList.length === 0) {
                    this.$message.warning("请选择至少一条数据");
                    return;
                }
                this.$confirm("确定将选择数据删除?", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        return remove(this.ids);
                    })
                    .then(() => {
                        this.onLoad(this.page);
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                        this.$refs.crud.toggleSelection();
                    });
            },
            beforeOpen(done, type) {
                if (["edit", "view"].includes(type)) {
                    getDetail(this.form.id).then(res => {
                        this.form = res.data.data;
                    });
                }
                done();
            },
            searchReset() {
                this.query = {};
                this.onLoad(this.page);
            },
            searchChange(params, done) {
                this.query = params;
                this.page.currentPage = 1
                this.onLoad(this.page, params);
                done();
            },
            selectionChange(list) {
                this.selectionList = list;
            },
            selectionClear() {
                this.selectionList = [];
                this.$refs.crud.toggleSelection();
            },
            currentChange(currentPage){
                this.page.currentPage = currentPage;
            },
            sizeChange(pageSize){
                this.page.pageSize = pageSize;
            },
            refreshChange() {
                this.onLoad(this.page, this.query);
            },
            onLoad(page, params = {}) {
                this.loading = true;
                getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
                    const data = res.data.data;
                    this.page.total = data.total;
                    this.data = data.records;
                    this.loading = false;
                    this.selectionClear();
                });
            },
            opened() {
                console.log("opened")
            },
            closed() {
                this.$emit("success");
            }
        }
    };
</script>

<style>
</style>
